package com.caifeng.myapplication;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class OneListAdapter extends BaseAdapter {

    private List<OneData> mList;
    private LayoutInflater inflater;
    private Context context;

    public OneListAdapter(List<OneData> mList, Context context) {
        this.mList = mList;
        this.context = context;
        inflater = LayoutInflater.from(context);//初始化布局加载器

    }

    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
//   序号
    }

    private class ViewHolder {

        private TextView name, message;
        private ImageView pic;
        private EditText ed;
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    @Override
    public int getViewTypeCount() {
        return 8;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;

        if (convertView == null) {
            switch (position) {
                case 0:
                    viewHolder = new ViewHolder();
                    convertView = inflater.inflate(R.layout.one_search, null);
                    viewHolder.ed = convertView.findViewById(R.id.for_search);
                    break;

                case 1:
                    viewHolder = new ViewHolder();
                    OneData mOneData = mList.get(position);
                    convertView = inflater.inflate(R.layout.one_message, null);
                    viewHolder.pic = convertView.findViewById(R.id.item_pic);
                    viewHolder.name = convertView.findViewById(R.id.item_name);
                    viewHolder.message = convertView.findViewById(R.id.item_message);
                    viewHolder.name.setText(mOneData.getItemName());
                    viewHolder.message.setText(mOneData.getItemMessage());
                    viewHolder.pic.setImageResource(mOneData.getItemPic());
                    break;
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                    viewHolder = new ViewHolder();
                    mOneData = mList.get(position);
                    convertView = inflater.inflate(R.layout.one_message, null);
                    viewHolder.pic = convertView.findViewById(R.id.item_pic);
                    viewHolder.name = convertView.findViewById(R.id.item_name);
                    viewHolder.message = convertView.findViewById(R.id.item_message);

                    viewHolder.name.setText(mOneData.getItemName());
                    viewHolder.message.setText(mOneData.getItemMessage());
                    viewHolder.pic.setImageResource(mOneData.getItemPic());

                    break;
            }
        }


        return convertView;
    }


}
